```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Zookeeper 架构设计解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4, h5, h6 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .drop-cap::first-letter {
            font-size: 3.5em;
            float: left;
            line-height: 0.8;
            margin: 0.1em 0.1em 0 0;
            color: #6e8efb;
            font-weight: 700;
        }
        .mermaid {
            background-color: #f8fafc;
            border-radius: 0.5rem;
            padding: 1.5rem;
            margin: 2rem 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col items-center text-center">
                <h1 class="text-4xl md:text-5xl font-bold mb-6">Zookeeper 架构设计解析</h1>
                <p class="text-xl md:text-2xl max-w-3xl mb-8 opacity-90">探索分布式协调服务的核心组件与设计精髓</p>
                <div class="w-24 h-1 bg-white opacity-50 mb-10"></div>
                <p class="text-lg max-w-3xl leading-relaxed drop-cap">Zookeeper 的架构设计通过这些核心组件相互配合，使其具备了高可用、高性能、强一致性和易扩展等特性，成为分布式系统中可靠的协调服务。每个组件在整个集群中扮演着特定的角色，确保了 Zookeeper 的稳定运行和高效运作。</p>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl py-16 px-4">
        <!-- Architecture Diagram -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-8 text-center">Zookeeper 架构概览</h2>
            <div class="mermaid">
                graph TD
                    A[Client] -->|读请求| B(Follower)
                    A -->|读请求| C(Observer)
                    A -->|写请求| D(Leader)
                    D -->|提案广播| B
                    D -->|提案广播| C
                    B -->|投票| D
                    D -->|数据同步| E[(Znode 数据树)]
                    B -->|数据同步| E
                    C -->|数据同步| E
                    F[Transaction Log] --> E
                    G[Snapshot] --> E
                    H[Zookeeper Ensemble] --> D
                    H --> B
                    H --> C
            </div>
            <div class="text-center mt-4 text-gray-600">
                <p>交互式架构图展示了 Zookeeper 各组件之间的交互关系</p>
            </div>
        </section>

        <!-- Components Section -->
        <section>
            <h2 class="text-3xl font-bold mb-8 text-center">核心组件详解</h2>
            
            <!-- Leader -->
            <div class="grid grid-cols-1 md:grid-cols-3 gap-8 mb-12">
                <div class="md:col-span-1">
                    <div class="bg-white rounded-xl shadow-lg p-6 h-full card-hover">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                                <i class="fas fa-crown text-blue-500 text-xl"></i>
                            </div>
                            <h3 class="text-2xl font-bold text-blue-600">Leader</h3>
                        </div>
                        <p class="text-gray-700 mb-4">在 Zookeeper 集群中，Leader 是唯一一个负责处理所有写请求的节点。</p>
                        <ul class="space-y-2 text-gray-600">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-400 mt-1 mr-2"></i>
                                <span>处理客户端的写请求</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-400 mt-1 mr-2"></i>
                                <span>发起并管理 ZAB 协议</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-400 mt-1 mr-2"></i>
                                <span>确保集群数据同步</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-400 mt-1 mr-2"></i>
                                <span>负责协调集群节点状态</span>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="md:col-span-2">
                    <div class="bg-white rounded-xl shadow-lg p-6 h-full card-hover">
                        <h4 class="text-xl font-semibold mb-4 text-gray-800">详细功能</h4>
                        <p class="text-gray-700 mb-4">所有的写操作（如创建、删除、修改节点等）都需要先发送到 Leader，Leader 会将这些操作按顺序应用到自身的内存状态中，并将操作的提案（Proposal）广播给所有的 Follower 节点。</p>
                        <div class="bg-blue-50 p-4 rounded-lg border-l-4 border-blue-500">
                            <p class="text-blue-700"><i class="fas fa-info-circle mr-2"></i>Leader 通过 Paxos 协议（ZAB 协议）确保数据的顺序一致性和可靠性。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Follower -->
            <div class="grid grid-cols-1 md:grid-cols-3 gap-8 mb-12">
                <div class="md:col-span-1">
                    <div class="bg-white rounded-xl shadow-lg p-6 h-full card-hover">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 rounded-full bg-purple-100 flex items-center justify-center mr-4">
                                <i class="fas fa-users text-purple-500 text-xl"></i>
                            </div>
                            <h3 class="text-2xl font-bold text-purple-600">Follower</h3>
                        </div>
                        <p class="text-gray-700 mb-4">Follower 是 Zookeeper 集群中的从节点，主要用于处理读请求和同步 Leader 的状态。</p>
                        <ul class="space-y-2 text-gray-600">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-400 mt-1 mr-2"></i>
                                <span>处理客户端的读请求</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-400 mt-1 mr-2"></i>
                                <span>接受并应用 Leader 的写提案</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-400 mt-1 mr-2"></i>
                                <span>参与 Leader 选举</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-400 mt-1 mr-2"></i>
                                <span>监控 Leader 的健康状态</span>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="md:col-span-2">
                    <div class="bg-white rounded-xl shadow-lg p-6 h-full card-hover">
                        <h4 class="text-xl font-semibold mb-4 text-gray-800">详细功能</h4>
                        <p class="text-gray-700 mb-4">每个 Follower 从 Leader 那里接受提案，然后参与投票以达成一致性。如果当前 Leader 宕机或者失去联系，Follower 节点会参与新 Leader 的选举过程。</p>
                        <div class="bg-purple-50 p-4 rounded-lg border-l-4 border-purple-500">
                            <p class="text-purple-700"><i class="fas fa-lightbulb mr-2"></i>读操作在任何一个 Follower 节点上都是一致的，这提高了系统的读取性能。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Observer -->
            <div class="grid grid-cols-1 md:grid-cols-3 gap-8 mb-12">
                <div class="md:col-span-1">
                    <div class="bg-white rounded-xl shadow-lg p-6 h-full card-hover">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 rounded-full bg-green-100 flex items-center justify-center mr-4">
                                <i class="fas fa-eye text-green-500 text-xl"></i>
                            </div>
                            <h3 class="text-2xl font-bold text-green-600">Observer</h3>
                        </div>
                        <p class="text-gray-700 mb-4">Observer 是一种特殊类型的 Zookeeper 节点，它可以连接到集群中但不参与写请求的投票。</p>
                        <ul class="space-y-2 text-gray-600">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-400 mt-1 mr-2"></i>
                                <span>处理客户端的读请求</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-400 mt-1 mr-2"></i>
                                <span>参与集群状态更新但不投票</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-400 mt-1 mr-2"></i>
                                <span>提升读性能而不影响写性能</span>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="md:col-span-2">
                    <div class="bg-white rounded-xl shadow-lg p-6 h-full card-hover">
                        <h4 class="text-xl font-semibold mb-4 text-gray-800">详细功能</h4>
                        <p class="text-gray-700 mb-4">Observer 的主要目的是增加系统的读取扩展性，降低 Leader 的负载，同时不会影响写操作的性能。对于不需要严格一致性的读操作场景，Observer 可以很有效地提升读性能。</p>
                        <div class="bg-green-50 p-4 rounded-lg border-l-4 border-green-500">
                            <p class="text-green-700"><i class="fas fa-chart-line mr-2"></i>在大规模集群中，Observer 可以显著提升系统的读取吞吐量。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Client -->
            <div class="grid grid-cols-1 md:grid-cols-3 gap-8 mb-12">
                <div class="md:col-span-1">
                    <div class="bg-white rounded-xl shadow-lg p-6 h-full card-hover">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 rounded-full bg-orange-100 flex items-center justify-center mr-4">
                                <i class="fas fa-laptop-code text-orange-500 text-xl"></i>
                            </div>
                            <h3 class="text-2xl font-bold text-orange-600">Client</h3>
                        </div>
                        <p class="text-gray-700 mb-4">Client 是使用 Zookeeper 服务的外部应用程序或服务，负责发起请求到 Zookeeper 集群。</p>
                        <ul class="space-y-2 text-gray-600">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-orange-400 mt-1 mr-2"></i>
                                <span>发送读/写请求到集群</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-orange-400 mt-1 mr-2"></i>
                                <span>管理与 Zookeeper 的会话</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-orange-400 mt-1 mr-2"></i>
                                <span>设置 Watcher 监听数据变化</span>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="md:col-span-2">
                    <div class="bg-white rounded-xl shadow-lg p-6 h-full card-hover">
                        <h4 class="text-xl font-semibold mb-4 text-gray-800">详细功能</h4>
                        <p class="text-gray-700 mb-4">客户端和 Zookeeper 之间保持长连接，并使用心跳机制来维持会话。客户端可以设置 Watcher（观察者）来监听 Znode 的数据变化或状态变化，实现通知机制。</p>
                        <div class="bg-orange-50 p-4 rounded-lg border-l-4 border-orange-500">
                            <p class="text-orange-700"><i class="fas fa-bell mr-2"></i>Watcher 机制是 Zookeeper 实现分布式协调功能的核心特性之一。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Znode -->
            <div class="grid grid-cols-1 md:grid-cols-3 gap-8 mb-12">
                <div class="md:col-span-1">
                    <div class="bg-white rounded-xl shadow-lg p-6 h-full card-hover">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 rounded-full bg-red-100 flex items-center justify-center mr-4">
                                <i class="fas fa-folder-tree text-red-500 text-xl"></i>
                            </div>
                            <h3 class="text-2xl font-bold text-red-600">Znode</h3>
                        </div>
                        <p class="text-gray-700 mb-4">Znode 是 Zookeeper 的核心数据结构，类似于文件系统中的节点。</p>
                        <ul class="space-y-2 text-gray-600">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-red-400 mt-1 mr-2"></i>
                                <span>树状数据结构组织和管理</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-red-400 mt-1 mr-2"></i>
                                <span>支持临时/持久/有序节点</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-red-400 mt-1 mr-2"></i>
                                <span>支持 Watcher 机制</span>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="md:col-span-2">
                    <div class="bg-white rounded-xl shadow-lg p-6 h-full card-hover">
                        <h4 class="text-xl font-semibold mb-4 text-gray-800">详细功能</h4>
                        <p class="text-gray-700 mb-4">所有的数据都是存储在这些 Znode 中，每个 Znode 可以存储数据内容和子节点的集合。支持临时节点（Ephemeral）、持久节点（Persistent）和有序节点（Sequential），适应不同的使用场景。</p>
                        <div class="bg-red-50 p-4 rounded-lg border-l-4 border-red-500">
                            <p class="text-red-700"><i class="fas fa-sitemap mr-2"></i>Znode 的树状结构设计使得数据组织非常灵活，适合各种分布式协调场景。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Ensemble -->
            <div class="grid grid-cols-1 md:grid-cols-3 gap-8 mb-12">
                <div class="md:col-span-1">
                    <div class="bg-white rounded-xl shadow-lg p-6 h-full card-hover">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                                <i class="fas fa-network-wired text-indigo-500 text-xl"></i>
                            </div>
                            <h3 class="text-2xl font-bold text-indigo-600">Zookeeper Ensemble</h3>
                        </div>
                        <p class="text-gray-700 mb-4">一个 Zookeeper 集群（Ensemble）是由多个 Zookeeper 服务器节点组成的。</p>
                        <ul class="space-y-2 text-gray-600">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-400 mt-1 mr-2"></i>
                                <span>提供可靠的分布式协调服务</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-400 mt-1 mr-2"></i>
                                <span>确保数据的高可用性和持久性</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-400 mt-1 mr-2"></i>
                                <span>通过选举机制保证集群可用</span>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="md:col-span-2">
                    <div class="bg-white rounded-xl shadow-lg p-6 h-full card-hover">
                        <h4 class="text-xl font-semibold mb-4 text-gray-800">详细功能</h4>
                        <p class="text-gray-700 mb-4">通常是奇数个节点（例如3、5、7等）。集群的存在是为了实现高可用性和数据的强一致性。确保集群中的所有节点都有相同的数据副本，从而保证数据的高可用性和持久性。通过选举机制，确保集群在任何时候都有一个可用的 Leader。</p>
                        <div class="bg-indigo-50 p-4 rounded-lg border-l-4 border-indigo-500">
                            <p class="text-indigo-700"><i class="fas fa-shield-alt mr-2"></i>奇数个节点的设计是为了在选举时能够形成多数派，避免脑裂问题。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Transaction Log & Snapshot -->
            <div class="grid grid-cols-1 md:grid-cols-3 gap-8 mb-12">
                <div class="md:col-span-1">
                    <div class="bg-white rounded-xl shadow-lg p-6 h-full card-hover">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 rounded-full bg-amber-100 flex items-center justify-center mr-4">
                                <i class="fas fa-database text-amber-500 text-xl"></i>
                            </div>
                            <h3 class="text-2xl font-bold text-amber-600">日志与快照</h3>
                        </div>
                        <p class="text-gray-700 mb-4">日志和快照是 Zookeeper 的持久化机制，用于保证数据的可靠性和恢复能力。</p>
                        <ul class="space-y-2 text-gray-600">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-amber-400 mt-1 mr-2"></i>
                                <span>事务日志记录所有写请求</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-amber-400 mt-1 mr-2"></i>
                                <span>定期保存内存数据快照</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-amber-400 mt-1 mr-2"></i>
                                <span>加快故障恢复速度</span>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="md:col-span-2">
                    <div class="bg-white rounded-xl shadow-lg p-6 h-full card-hover">
                        <h4 class="text-xl font-semibold mb-4 text-gray-800">详细功能</h4>
                        <p class="text-gray-700 mb-4">每个写请求都会被记录到事务日志中。即使节点宕机或重启，也可以通过日志恢复到一致的状态。定期将内存中的数据快照保存到磁盘上，以减少在恢复时需要重放的事务日志条目的数量，加快恢复速度。</p>
                        <div class="bg-amber-50 p-4 rounded-lg border-l-4 border-amber-500">
                            <p class="text-amber-700"><i class="fas fa-history mr-2"></i>日志+快照的组合确保了数据的安全性和恢复的高效性。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Summary Section -->
        <section class="bg-white rounded-xl shadow-lg p-8 mb-16 card-hover">
            <h2 class="text-3xl font-bold mb-6 text-center">架构设计价值</h2>
            <div class="grid grid-cols-1 md:grid-cols-4 gap-6">
                <div class="text-center p-4">
                    <div class="w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center mx-auto mb-4">
                        <i class="fas fa-bolt text-blue-500 text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-2">高可用</h3>
                    <p class="text-gray-600">集群部署，自动故障转移</p>
                </div>
                <div class="text-center p-4">
                    <div class="w-16 h-16 bg-purple-100 rounded-full flex items-center justify-center mx-auto mb-4">
                        <i class="fas fa-tachometer-alt text-purple-500 text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-2">高性能</h3>
                    <p class="text-gray-600">读写分离，Observer扩展</p>
                </div>
                <div class="text-center p-4">
                    <div class="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4">
                        <i class="fas fa-link text-green-500 text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-2">强一致性</h3>
                    <p class="text-gray-600">ZAB协议保证数据一致</p>
                </div>
                <div class="text-center p-4">
                    <div class="w-16 h-16 bg-indigo-100 rounded-full flex items-center justify-center mx-auto mb-4">
                        <i class="fas fa-expand text-indigo-500 text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-2">易扩展</h3>
                    <p class="text-gray-600">灵活增加Observer节点</p>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="container mx-auto px-4">
            <div class="flex flex-col items-center">
                <h3 class="text-xl font-semibold text-white mb-2">技术小馆</h3>
                <a href="http://www.yuque.com/jtostring" class="text-gray-400 hover:text-white transition-colors duration-200">
                    www.yuque.com/jtostring
                </a>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```